$(function(argument) {
	var backOne = window.sessionStorage.getItem("backOne");
	var backCity = window.sessionStorage.getItem("backCity");
	// 渲染省份
	$.ajax({
		url: 'http://www.teaweilai.com/app/Admin/Mallcat/CityShow',
		type: 'post',
		dataType: 'json',
		success: function(data) {
			console.log(data);
			// 渲染省份
			var leftLi = template("province", {
				province: data
			});
			$(".left ul").html(leftLi);
			// 渲染第一个省的城市
			var region_id = data.sing[0].region_id;

			$.ajax({
					url: 'http://www.teaweilai.com/app/Admin/Mallcat/CitySon',
					type: 'POST',
					dataType: 'json',
					data: {
						region_id: region_id
					},
					beforeSend: function() {
						console.log(region_id);
					},
					success: function(dataSon) {
						console.log(dataSon);
						var cityList = template("cityList", {
							cityList: dataSon
						});
						$(".right ul").html(cityList);
					}
				})
				.done(function() {
					console.log("success");
				})
				.fail(function() {
					console.log("error");
				})
		}
	})



	//渲染市
	var region_id = 52; // 默认北京的
	$(document).on("click", ".provinceOne", function() {
			region_id = $(this).eq(0).eq(0).attr("data-region_id");
			console.log($(this).eq(0).parents("li").eq(0));
			$(this).eq(0).parents("li").siblings('li').children('a').removeClass('current');
			$(this).eq(0).addClass('current');

			$.ajax({
				url: 'http://www.teaweilai.com/app/Admin/Mallcat/CitySon',
				type: 'POST',
				dataType: 'json',
				data: {
					region_id: region_id
				},
				success: function(dataSon) {
					console.log(dataSon);

					var cityList = template("cityList", {
						cityList: dataSon
					});
					$(".right ul").html(cityList);
				}
			})
		})
		// 点击市
	$(document).on("click", ".city", function() {
		//console.log($(this))
		// var region_id = $(this).eq(0).eq(0).attr("data-region_id");
		var region_name = $(this).eq(0).eq(0).html();
		window.sessionStorage.setItem("region_id", region_id);
		window.sessionStorage.setItem("region_name", region_name);

		if (backOne != null) {
			window.sessionStorage.removeItem("backCity");
			window.location.href = "oneForone.html";

		}
		if (backCity != null) {
			window.sessionStorage.removeItem("backCity");
			window.location.href = "cityShop.html";

		}
	})
	$(".glyphicon-menu-left").click(function(e) {
		e.preventDefault();
		window.history.back();
	})
})